const fs = require('fs');

const scripts = ['18384/字体样式美化',
    '495660/TM Color Change(Beta)',
    '493854/TMGeneralTranslation',
    '400850/RatingR5 CN beta',
    '377184/TM hide scouts and show skills CN',
    '481370/TM Skill Index Calculator CN',
    '426396/TM Trader\'s Calculator (CN beta)',
    '493921/TM Value Variation Calculator CN',
    '494169/TrainSimulator',
    '431931/TMVN Players Scout (CN beta)',
    '429278/球员比较雷达图 Raydar Pictures in the “compare players“ page',
    '470342/TM Compare Others\' Players CN',
    '426387/TMVN Club Transfer (CN beta)',
    '426389/TMVN Club HeadToHead (CN beta)',
    '426390/TMVN Home HeadToHead (CN beta)',
    '431933/TMVN Squad Hide (CN beta)',
    '493678/TMVN Club Finance CN',
    '426388/TMVN Squad Value(CN beta)',
    '431930/TM Super Detailed Club Page CN beta',
    '431932/TMVN Players Train (CN beta 暂时不兼容暴力猴)',
    '439322/球队年龄结构图',
    '511604/TM LocalStorage ExporterImporter',
    '494009/TM Routine Line Sharing + Advanced Players Infos',
    '13757/TM_enhanced_co_editor (CN)',
    '374348/Save Tactics_CO\'s  CN',
    '493985/TM Free Tactics Filter 免费的战术过滤器',
    '12464/Match Analyzer Report CN',
    '426392/MatchResult_GoalScorers',
    '439866/TMVN Match Event(CN Beta)',
    '377182/TM Match Infos (CN beta)',
    '405681/My Match Analyzer CN',
    '29537/Fincance Plus',
    '453777/Match Analysis',
    '431929/TM League Match History CN',
    '426385/TMVN League Lineup (CN beta)',
    '377207/League Result',
    '451964/TM League Chart by rounds',
    '493984/TM Export League Table Copy to Clipboard',
    '493991/TM Friendly League Match History CN',
    '493977/TM Friendly League Chart by rounds CN',
    '377186/TM Super Detailed National Club Page',
    '373829/ASI and Routine in representation',
    '494008/TM Country teams INT matches',
    '502065/TM 转会助手A',
    '497724/TM 转会助手B（Beta）',
    '29180/Show Youth SI',
    '497085/TM League Calculater(CN)',
    '439874/TM Training History (CN)',
    '535588/TMVN League InOut',
    '418934/TMVN League HOF',
    '418935/TMVN Cup HOF'
]


scripts.forEach(script => {
    // 读取文件内容
    const filePath = script + '.user.js';
    const fileContent = fs.readFileSync(filePath, 'utf8');

    // 调用函数修改文件内容
    const updatedContent = modifyJSFile(fileContent);

    // 将修改后的内容写回文件
    fs.writeFileSync(filePath, updatedContent, 'utf8');

    function modifyJSFile(fileContent) {
        // 使用正则表达式查找并替换 @downloadURL 和 @updateURL
        return fileContent.replace(/update\.greasyfork\.org\/scripts/g,
            'gitee.com/trophymanagerCN/tmjs/raw/master')
    }
})
